package com.catmiw.stock.service;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.catmiw.stock.dao.CapitalChangeMapper;
import com.catmiw.stock.domain.CapitalChange;

public class CapitalServiceImpl implements CapitalService {

	public int insertAll(List<CapitalChange> ins) {
		SqlSession session=SessionFactory.getInstance().getSession();
		CapitalChangeMapper cm=session.getMapper(CapitalChangeMapper.class);
		int count=0;
		
		for (CapitalChange icm:ins){
			cm.insert(icm);
			count++;
		}
		session.commit();
		session.close();
		
		return count;
	}

	public void deleteAll() {
		SqlSession session=SessionFactory.getInstance().getSession();
		CapitalChangeMapper cm=session.getMapper(CapitalChangeMapper.class);
		cm.deleteAll();
		session.commit();
		session.close();
	}

	public List<CapitalChange> selectByCode(String code) {
		SqlSession session=SessionFactory.getInstance().getSession();
		CapitalChangeMapper cm=session.getMapper(CapitalChangeMapper.class);
		
		//List<CapitalChange> lcc=(List<CapitalChange>)(session.selectList(
		//		"com.catmiw.stock.CapitalChange.selectCode", code));
		
		List<CapitalChange> lcc=(List<CapitalChange>)(cm.selectCode(code));
		session.commit();
		session.close();
		return lcc;
	}

}
